import { fromError, initAxios, type ApiResponse } from "../common";

const client = initAxios();

export type CountByDate = {
  date: string;
  count: number;
};

export async function commentCountByDateLastMonth() {
  try {
    const resp = await client.get<ApiResponse<CountByDate[]>>('/api/stats/comment');
    return resp.data;
  } catch (error) {
    return fromError(error);
  }
}

export async function novelCountByDateLastMonth() {
  try {
    const resp = await client.get<ApiResponse<CountByDate[]>>('/api/stats/novel');
    return resp.data;
  } catch (error) {
    return fromError(error);
  }
}

export async function userCountByDateLastMonth() {
  try {
    const resp = await client.get<ApiResponse<CountByDate[]>>('/api/stats/user');
    return resp.data;
  } catch (error) {
    return fromError(error);
  }
}
